﻿using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxImageSlider;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utility1;

namespace eDream.Page
{
    public partial class detail : System.Web.UI.UserControl
    {
        public string pathUrl;
        public string cateId = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            pathUrl = WebUtils.pathUrl();
            /*
            if (HttpContext.Current.Request.RequestContext.RouteData.Values["k"] != null)
                cateId = HttpContext.Current.Request.RequestContext.RouteData.Values["k"].ToString();
             */
            cateId = Utils.GetParameter("k", "0");
            if (!IsPostBack)
                bindata();
        }

        void bindata()
        {
            DataClasses1DataContext dx = new DataClasses1DataContext();
            try
            {
                
                string nam = "";

                if (Request.QueryString["n"] != null)
                    nam = Request.QueryString["n"];
                hdflinklike.Value = WebUtils.pathUrl() + "/San-pham/" + cateId + "/" + nam+".html";
                dx.Connection.Open();
                var list = from k in dx.Product_tbs
                           where k.ID == int.Parse(cateId)
                           select k;
                foreach (Product_tb p in list)
                {
                    Page.Title = p.iProName;
                    Page.MetaDescription = Utils.RemoveHtmlTagsUsingRegex(p.MetaDescription);
                    Page.MetaKeywords = p.MetaKeywords;

                    lbChitiet.Text = p.iDersc;
                    lbTinhnang.Text = p.iTinhnang;
                    lbHinhanh.Text = p.iPhoto;
                    lbVideo.Text = p.iVideo;
                    //lbmsp.Text=p.m
                    if(p.iDongiamoi>0)
                    lbGia.Text = "Giá: "+ Utils.GetMoneyString((double)p.iDongia) +" VND";
                    hdftensanp.Value = p.iProName;
                    ImageSliderItem item = new ImageSliderItem();
                    item.ImageUrl = pathUrl+ "/Image/product/"+p.hinh1;
                            
                    ASPxImageSlider1.Items.Add(item);

                    item = new ImageSliderItem();
                    item.ImageUrl = pathUrl + "/Image/product/" + p.hinh2;
               
                    ASPxImageSlider1.Items.Add(item);

                    item = new ImageSliderItem();
                    item.ImageUrl = pathUrl + "/Image/product/" + p.hinh3;
            
                    ASPxImageSlider1.Items.Add(item);

                    item = new ImageSliderItem();
                    item.ImageUrl = pathUrl + "/Image/product/" + p.hinh4;

                    ASPxImageSlider1.Items.Add(item);

                    item = new ImageSliderItem();
                    item.ImageUrl = pathUrl + "/Image/product/" + p.hinh5;

                    ASPxImageSlider1.Items.Add(item);

                   // ASPxImageSlider1.SettingsImageArea.AnimationType = AnimationType.Slide;
                    ASPxImageSlider1.SettingsImageArea.NavigationDirection = NavigationDirection.Horizontal;
                    ASPxImageSlider1.SettingsImageArea.ImageSizeMode = ImageSizeMode.FillAndCrop;
                    ASPxImageSlider1.SettingsImageArea.NavigationButtonVisibility = NavigationButtonVisibilityMode.Always;
                    ASPxImageSlider1.SettingsImageArea.ItemTextVisibility = ItemTextVisibilityMode.Always;

                    ASPxImageSlider1.SettingsNavigationBar.Position = NavigationBarPosition.Bottom;
                    ASPxImageSlider1.SettingsNavigationBar.Mode = NavigationBarMode.Thumbnails;
 

                    //ASPxImageSlider1.SettingsBehavior.EnablePagingByClick = true;
                    //ASPxImageSlider1.SettingsBehavior.EnablePagingGestures = true;
                    ASPxImageSlider1.SettingsBehavior.ImageLoadMode = ImageLoadMode.DynamicLoadAndCache;
         
                }
            }
            catch (Exception) { }
            finally { dx.Connection.Close(); }
        }

        protected void btnAddcart_Click(object sender, EventArgs e)
        {
            string link = pathUrl + "/Gio-hang/" + cateId + "/" + txtSoluong.Value+".html";
            Response.Redirect(link);
        }

       
        
    }
}